$(function () {
    /*删除*/
    $('#deleteActive').click(function () {
        var orderId=$('#deleteId').val();
        $.ajax({
            url:ctx+"homeHigh/deleteOrderById?id="+orderId,
            type:"post",
            dataType:"json",
            success : function (data) {
                if (data.msg == '删除成功'){
                    $('#deleteModal').modal('hide');
                    toastr.success("删除成功");
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                }
                else {
                    toastr.error("操作失败")
                }
            }
        })
    })

    /*评论*/
    $('#reviewActive').click(function () {
        var resultJson={};
        resultJson.hotelId=$('#hotelId').val();
        resultJson.userPhone=$('#userPhone').val();
        resultJson.orderId=$('#orderId').val();    //3.21 还未想到用处 预存一下
        resultJson.hotelNameRoom=$('#hotelNameRoom').val();
        resultJson.reviewAll=$('#reviewAll').val();
        if($('#reviewAll').val() == null || $('#reviewAll').val()== ''|| $('#reviewAll').val()=='null'){
            toastr.warning("您还未输入评价")
            return null
        }
        $.ajax({
            url:ctx+"homeHigh/review",
            type:"post",
            data:resultJson,
            dataType:"json",
            success :function (data) {
                if (data.msg == '评论成功'){
                    toastr.success("评论成功");
                    $('#reviewModal').modal('hide');
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                }else {
                    toastr.error(data.msg)
                }
                
            }
        })

        
    })

    /*追加评论*/
    $('#reviewAddActive').click(function () {
        var resultJson={};
        resultJson.orderId=$('#reviewAdd').val();
        resultJson.reviewAddAll='---'+$('#reviewAddAll').val();
        if($('#reviewAddAll').val() == null || $('#reviewAddAll').val()== ''|| $('#reviewAddAll').val()=='null'){
            toastr.warning("您还未输入评价");
            return null;
        }
        $.ajax({
            url:ctx+"homeHigh/reviewAdd",
            type:"post",
            data:resultJson,
            dataType:"json",
            success :function (data) {
                if (data.msg == '追评成功'){
                    toastr.success("追评成功");
                    $('#reviewAddModal').modal('hide');
                    setTimeout(function () {
                        window.location.reload();
                    },500)
                }else {
                    toastr.error(data.msg)
                }

            }
        })

    })
    $('#returnActive').click(function () {
        var resultJson={};
        resultJson.out_trade_no=$('#out_trade_no').val();
        resultJson.total_price=$('#total_price').val();
        resultJson.returnOrderId=$('#returnOrderId').val();
        resultJson.hotelId=$('#returnHotelId').val();
        resultJson.hotelRoom=$('#hotelRoom').val();
        resultJson.userPhone=userPhone;
        $.ajax( {
            url : ctx+"returnPay",
            type : "post",
            data:resultJson,
            dataType:"json",
            success :function (data) {
                console.info(data.msg)
                toastr.success(data.msg);
                $('#returnModal').modal('hide');
                setTimeout(function () {
                    window.location.reload();
                },500)

            }
        })

    })
})

    /*删除*/
    function deleteOrder(orderid){
        $('#deleteId').val(orderid);
    }

    /*评论*/
    function reviewOrder(userPhone,hotelId,orderId,hotelNameRoom) {
        $('#userPhone').val(userPhone);
        $('#hotelId').val(hotelId);
        $('#orderId').val(orderId);
        $('#hotelNameRoom').val(hotelNameRoom);
    }

    /*查看详情*/
    function scanInfoOrder(trade,user,userphone,peoples) {
        $('#trade').val(trade);
        $('#bookuser').val(user);
        $('#bookuserPhone').val(userphone);
        $('#peoples').val(peoples)
    }

    /*追加评论*/
    function reviewAddOrder(orderid) {
        $('#reviewAdd').val(orderid);

    }

    /*退款*/
    function returnOrder(out_trade_no,total_price,id,inTime,hotelId,hotelNameRoom) {
        var mydate = new Date().getTime();
        var inRoomTime=new Date(inTime+" "+"18:00:00").getTime();
        var timeChuo=new Date(inTime).getTime();
        if (mydate>inRoomTime){
            toastr.warning("已超时，不可退款")
            $('#returnActive').prop("disabled",true);
        }
      $('#out_trade_no').val(out_trade_no);
      $('#total_price').val(total_price);
      $('#returnOrderId').val(id);
      $('#return_price').val(total_price);
      $('#returnHotelId').val(hotelId);
      $('#hotelRoom').val(hotelNameRoom);
    }
